package com.ruoyi.edu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.edu.api.domain.EduChapter;
import com.ruoyi.edu.service.IEduChapterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程章节Controller
 * 
 * @author isahino
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/chapter")
public class EduChapterController extends BaseController
{
    @Autowired
    private IEduChapterService eduChapterService;

    /**
     * 查询课程章节列表
     */
    @RequiresPermissions("edu:chapter:list")
    @GetMapping("/list")
    public TableDataInfo list(EduChapter eduChapter)
    {
        startPage();
        List<EduChapter> list = eduChapterService.selectEduChapterList(eduChapter);
        return getDataTable(list);
    }

    /**
     * 导出课程章节列表
     */
    @RequiresPermissions("edu:chapter:export")
    @Log(title = "课程章节", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduChapter eduChapter)
    {
        List<EduChapter> list = eduChapterService.selectEduChapterList(eduChapter);
        ExcelUtil<EduChapter> util = new ExcelUtil<EduChapter>(EduChapter.class);
        util.exportExcel(response, list, "课程章节数据");
    }

    /**
     * 获取课程章节详细信息
     */
    @RequiresPermissions("edu:chapter:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(eduChapterService.selectEduChapterById(id));
    }

    /**
     * 新增课程章节
     */
    @RequiresPermissions("edu:chapter:add")
    @Log(title = "课程章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduChapter eduChapter)
    {
        return toAjax(eduChapterService.insertEduChapter(eduChapter));
    }

    /**
     * 修改课程章节
     */
    @RequiresPermissions("edu:chapter:edit")
    @Log(title = "课程章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduChapter eduChapter)
    {
        return toAjax(eduChapterService.updateEduChapter(eduChapter));
    }

    /**
     * 删除课程章节
     */
    @RequiresPermissions("edu:chapter:remove")
    @Log(title = "课程章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(eduChapterService.deleteEduChapterByIds(ids));
    }
}
